package com.yikome.product.repository;

import java.util.List;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.yikome.common.CommonRepository;
import com.yikome.product.entity.ProductAttribute;

@Repository
public interface ProductAttributeRepository extends CommonRepository<ProductAttribute, Long> {

    @Query("select pa from ProductAttribute pa where pa.yn = 1 and pa.productId = :productId order by pa.priority asc")
    List<ProductAttribute> findByProductId(@Param("productId") Long productId);

    void deleteByProductId(Long productId);

    @Query("select p from  ProductAttribute p where productId = :productId and LENGTH(name) > 0 and yn = 1 order by priority asc")
    List<ProductAttribute> findAllByProductId(@Param("productId") Long productId);
}
